{% extends 'base/base.html' %}

{% block title %}仪表盘 - 环保监测数据管理系统{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1 class="h2">仪表盘</h1>
        <div>
            <a href="{% url 'monitoring:data_create' %}" class="btn btn-primary">
                <i class="fas fa-plus"></i> 添加监测数据
            </a>
        </div>
    </div>
    
    <!-- 统计卡片 -->
    <div class="row">
        <div class="col-md-3 mb-4">
            <div class="card border-left-primary h-100 py-2">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
                                监测类别总数</div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800">{{ total_categories }}</div>
                        </div>
                        <div class="col-auto">
                            <i class="fas fa-tags fa-2x text-gray-300"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="col-md-3 mb-4">
            <div class="card border-left-success h-100 py-2">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-success text-uppercase mb-1">
                                监测数据总数</div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800">{{ total_data }}</div>
                        </div>
                        <div class="col-auto">
                            <i class="fas fa-database fa-2x text-gray-300"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="col-md-3 mb-4">
            <div class="card border-left-warning h-100 py-2">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-warning text-uppercase mb-1">
                                警告数据</div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800">{{ warning_count }}</div>
                        </div>
                        <div class="col-auto">
                            <i class="fas fa-exclamation-triangle fa-2x text-gray-300"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="col-md-3 mb-4">
            <div class="card border-left-danger h-100 py-2">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-danger text-uppercase mb-1">
                                危险数据</div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800">{{ danger_count }}</div>
                        </div>
                        <div class="col-auto">
                            <i class="fas fa-radiation fa-2x text-gray-300"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- 最近监测数据 -->
    <div class="row">
        <div class="col-12">
            <div class="card shadow mb-4">
                <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
                    <h6 class="m-0 font-weight-bold text-primary">最近监测数据</h6>
                    <a href="{% url 'monitoring:data_list' %}" class="btn btn-sm btn-primary">
                        查看全部
                    </a>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover">
                            <thead class="table-light">
                                <tr>
                                    <th>类别</th>
                                    <th>地点</th>
                                    <th>监测值</th>
                                    <th>单位</th>
                                    <th>状态</th>
                                    <th>监测时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for data in recent_data %}
                                <tr>
                                    <td>{{ data.category.name }}</td>
                                    <td>{{ data.location }}</td>
                                    <td>{{ data.value }}</td>
                                    <td>{{ data.unit }}</td>
                                    <td>
                                        {% if data.status == 'normal' %}
                                        <span class="badge bg-success">正常</span>
                                        {% elif data.status == 'warning' %}
                                        <span class="badge bg-warning">警告</span>
                                        {% elif data.status == 'danger' %}
                                        <span class="badge bg-danger">危险</span>
                                        {% endif %}
                                    </td>
                                    <td>{{ data.measured_at|date:"Y-m-d H:i" }}</td>
                                    <td>
                                        <a href="{% url 'monitoring:data_detail' data.id %}" class="btn btn-sm btn-info">
                                            <i class="fas fa-eye"></i>
                                        </a>
                                        <a href="{% url 'monitoring:data_update' data.id %}" class="btn btn-sm btn-primary">
                                            <i class="fas fa-edit"></i>
                                        </a>
                                    </td>
                                </tr>
                                {% empty %}
                                <tr>
                                    <td colspan="7" class="text-center">暂无监测数据</td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %} 